class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int fast = 0;
        int slow = 0;
        int n = nums.size();
        int newLen = n;
        while (fast < n)
        {
            if (nums[fast] != val) nums[slow++] = nums[fast++];
            else { ++fast; --newLen; }
        }
        return newLen;
    }
};